package org.prosim.framework.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;
import org.prosim.framework.Menu;
import org.prosim.util.FileUtils;
import org.prosim.util.XmlUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class FrameworkService {

	/**
	 * �����߲˵��б�
	 * 
	 * @return �˵��б�
	 * @throws IOException 
	 * @throws JDOMException 
	 */
	public List<Menu> leftsideMenus() throws JDOMException, IOException {
		String menuXml = FileUtils
				.getFilePathInPackage("/org/prosim/framework/menu.xml");
		if(menuXml == null)
			return new ArrayList<Menu>();
		
		Element rootMenus = XmlUtils.rootElement(menuXml);
		List<Element> eMenus = XmlUtils.selectNodes(rootMenus, "menu");
		List<Menu> menus = new ArrayList<Menu>();
		for (Element eMenu : eMenus) {
			menus.add(Menu.parse(eMenu));
		}
		return menus;
	}
}
